Overriding a method just to call the same method from the super class without performing any other actions is useless and misleading. The only time
this is justified is in final
overriding methods, where the effect is to lock in the parent class behavior. This rule ignores such
overrides of equals
, hashCode
and toString
.
Noncompliant code example
class Child extends Parent {
public function func($n,$m) {
parent::func($n$m); // Noncompliant
}
}
class Parent {
public function func($n, $m) {
// do something
}
}
Compliant solution
class Child extends Parent {
public function func($n,$m) {
parent::func($n$m);
// do additional things...
}
}
class Parent {
public function func($n, $m) {
// do something
}
}
or
class Child extends Parent {
// function eliminated
}
class Parent {
public function func($n, $m) {
// do something
}
}